<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/web/pub/head.inc"%>
<%@ include file="/pub/head_bootstrap.inc"%>
<%--<link href="${baseURL}/themes/default/css/sdApp.min.css" rel="stylesheet" type="text/css" />--%>
<title>菜单管理</title>
	<style>
.l-group span {
	float: none;
}

.l-text.l-text-combobox {
	width: 250px;
}

.FrameWindow .window-menu {
    width: 97%;
    margin: 10px 1%;
    position: fixed;
    top: 0px;
    text-align: left;
    background: #fff;
    border-bottom: 1px solid #dff0fe;
    z-index: 9;
    border: 1px solid rgba(233, 237, 247, 0.8);
}

.location, .bootstrap-dialog-header, .FirstMenu, .selecte-list, .describe {
	text-align: left;
}

</style>
</head>
<body id="mybody" style="background:#fff">
	<div class="FrameWindow tabFrameWindow">
		<div class="window-menu">
			<div class="menuInner">
				<button type="button" class="btn btn-normal btn-blue"
					onclick="FF_Save()">保存</button>
				<button type="button" class="btn btn-normal btn-white"
					onclick="ev_back(false)">取消</button>
			</div>
		</div>
		<!-- window-menu -->
		<div class="FrameWindowInner">
			<div class="location"
				style="height: 32px; letter-spacing: 2px; color: #525771">
				<i class="fa fa-map-marker"
					style="color: #2684ce; font-size: 18px; vertical-align: top; margin-right: 8px; margin-bottom: -2px"></i>菜单编辑
			</div>

			<!-- top-card -->

			<div class="cont-table tab-content">
				<!-- 机构信息 -->
				<div class="tab-pane fade in active" id="mainTab">
					<form onsubmit="return false;" id="mainform" class="table-normal" enctype="multipart/form-data">
						<div class="cont-table tab-content" style="width: 98%">
							<table>
								<tbody>
									<tr>
										<input type="hidden" name="id" id="id" value="${resource.id}">
									</tr>
									<tr>
										<input type="hidden" name="logLevelId" id="logLevelId"
											value="1">
									</tr>
									<tr>
										<th align="right"><font color="red">*</font>功能编号：</th>
										<td colspan="2"><input id="code" name="code" class="illegalRequest"
											type="text" value="${resource.code }"
											validate="{required:true}" /></td>
									</tr>
									<tr>
										<th align="right"><font color="red">*</font>功能名称：</th>
										<td colspan="2"><input maxlength="1000" inputwidth="365" id="name"
											name="name" class="illegalRequest" type="text"
											style="height: 30px" value="${resource.name}"
											validate="{required:true}" /></td>
									</tr>
									<tr>
										<th align="right">上级菜单：</th>
										<td style="border-right: none;">
											<input type="hidden" name="parentResourceId"
												   id="parentResourceId" value="${parentResourceId}">
											<input maxlength="1000"
													id="fullName" name="fullName" readOnly="readOnly"
													class=" illegalRequest " type="text"
													value="${parentResource.fullName}" />
										</td>
										<td style="width: 70px;border-left: none;padding-left: 0px;"><input
												style="width: 50px" id="btnMenuInfo" type="button"
												value="选择" class="btn btn-normal btn-blue" /></td>
									</tr>
									<tr>
										<th align="right">大图标：</th>
										<td colspan="2"><input id="bigIconPath" name="bigIconPath"
											class="illegalRequest" type="text"
											value="${resource.bigIconPath}"
											 /></td>
									</tr>
									<tr>
										<th align="right">小图标：</th>
										<td colspan="2"><input maxlength="1000" inputwidth="365"
											id="smallIconPath" name="smallIconPath"
											class="illegalRequest" type="text" style="height: 30px"
											value="${resource.smallIconPath}" /></td>
									</tr>
									<tr>
										<th align="right">样式class：</th>
										<td colspan="2"><input
											maxlength="1000" inputwidth="365" id="menuClass"
											name="menuClass" class="illegalRequest" type="text"
											style="height: 30px" value="${resource.menuClass}" /></td>
									</tr>
									<tr>
										<th align="right">类别：</th>
										<td colspan="2"><input type="hidden" id="resourceType"
											name="resourceType" value="${resource.resourceType}" /> <select
											name="resourceType">
												<option value="0" ${resource.resourceType == '0' ? 'selected' : '' }>菜单</option>
												<option value="1" ${resource.resourceType == '1' ? 'selected' : '' }>按钮</option>
										</select></td>
									</tr>
									<tr>
										<th align="right">排序号：</th>
										<td colspan="2"><input maxlength="1000" inputwidth="365"
											id="priority" name="priority" class="illegalRequest"
											type="text" style="height: 30px" value="${resource.priority}" /></td>
									</tr>
									<tr>
										<th align="right"><font color="red">*</font>目标窗体：</th>
										<td colspan="2"><input type="hidden" id="openTargetWindow"
											name="openTargetWindow" value="${resource.openTargetWindow}" />
											<select name="openTargetWindow">
												<option value="parent"
													${resource.openTargetWindow=='parent' ? 'selected' : ''}>父窗体</option>
												<option value="top"
													${resource.openTargetWindow=='top' ? 'selected' : ''}>顶级窗体</option>
												<option value="new"
													${resource.openTargetWindow=='new' ? 'selected' : ''}>新窗体</option>
												<option value=""
													${fn:contains('parent,top,new',resource.openTargetWindow) ? '' : 'selected'}>自定义</option>
										</select></td>
									</tr>
									<tr>
										<th align="right">是否账号菜单：</th>
										<td colspan="2" style="text-align: left;">
										<input type="hidden" id="isAccountMenu"
											name="isAccountMenu" value="${resource.isAccountMenu}" />
										<select name="isAccountMenu">
												<option value="0"
													${resource.isAccountMenu == '0' ? 'selected' : '' }>否
													</optgroup>
													<option value="1"
														${resource.isAccountMenu == '1' ? 'selected' : '' }>是
														</optgroup>
										</select> <span style="font-style: italic; color: red;">该菜单需为第一级菜单</span>
										</td>
									</tr>
									<tr>
										<th align="right">URL：</th>
										<td colspan="2"><textarea name="url" cols="50" rows="6"
												showName="URL" check="isString('#',250)" required="nullable">${resource.url }</textarea></td>
									</tr>
								</tbody>
							</table>
						</div>
					</form>

				</div>
			</div>

		<script type="text/javascript">
		//parent.ChangeIframeHeight("fform","800px");
		//编辑，新增
		var mainform = $("#mainform");
		//添加验证
		jQuery.metadata.setType("attr", "validate");
		
		//保存
		function FF_Save() {
			var resourceType = $("select[name=resourceType]").val();
			$("#resourceType").val(resourceType);
			var openTargetWindow =  $("select[name=openTargetWindow]").val();
			$("#openTargetWindow").val(openTargetWindow);
			var isAccountMenu = $("select[name=isAccountMenu]").val();
			$("#isAccountMenu").val(isAccountMenu);
			var win = parent || window;
			var resourceId = '${resource.id }';
			if(resourceId==""){
				mainform.attr("action","${ROOT}/system/security/resource/createResourceForJSON.do?flag=0");
			}else{
				mainform.attr("action","${ROOT}/system/security/resource/updateResourceForJSON.do?flag=0");
			}
			BT.submitForm(mainform, function(data) {
				var win = parent || window;
				if (data.hasOk) {
					try {
	    				BT.showSuccess('操作成功!',function(){
	    					// 关闭窗口 刷新父窗口
	    					ev_back(true);
	    				});
					} catch (e) {
	    				BT.showSuccess('操作成功!',function(){
	    					// 关闭窗口 刷新父窗口
	    					ev_back(true);
	    				});
					}
				} else {
					BT.showError("操作失败!失败信息如下:\n" + data.message + "\n如您对以上信息有疑问，请联系管理人员!");
				}
			});
		}
		function ev_back(flgEdit){
			var url = "${ROOT}/system/security/resource/listResource.do?parentResourceId=${parentResourceId }";
			pageShowList(url,flgEdit);
		}

        $("#btnMenuInfo").click(function(){
            $(this).btAddressBook({
                openType : "dialog",
                type : 600,
                selectType:20,
                num: 1,
                callback: function(msg) {
                    // 验证是否为自己子节点
					var param = msg.data[0].param.split('!@!')
					var currentMenuId = $('input[name="id"]').val()

                    if (!validChooseMenu(param[1], msg.ids, currentMenuId)) {
                        return;
                    }

                    $('input[name="parentResourceId"]').val(msg.ids)
                    $('input[name="fullName"]').val(param[0])
				}
            })
        });

		/*
		 * 验证选择上级菜单是否有效
		 * 无效上级菜单有下面两种情况
		 *   - 选择的菜单 == 当前编辑的菜单
		 *   - 选择的菜单是当前编辑菜单的子孙节点
		 */
		function validChooseMenu(fullPath, chooseMenuId, currentMenuId) {
		    // 没有id时是新增操作，放到哪个菜单下都可以，不需要做验证
		    if (!currentMenuId) {
		        return true;
            }

            if (chooseMenuId == currentMenuId) {
                BT.showWarning('不能选择自己')
                return false;
            }

            var currentIdIndex = fullPath.indexOf(currentMenuId)
            if (currentIdIndex != -1) {
                var index = fullPath.indexOf(chooseMenuId)
                if (currentIdIndex < index) {
                    BT.showWarning('不能移动到子节点去')
                    return false
                }
            }
            return true;
        }
	</script>
</body>
</html>